package com.usefullc.user.controller.admin;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.usefullc.system.controller.BaseController;
import com.usefullc.system.controller.WebResultBuilder;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.entity.WebResult;
import com.usefullc.system.param.IdsParam;
import com.usefullc.system.validator.UsefulValid;
import com.usefullc.user.param.EmployeeEditParam;
import com.usefullc.user.query.EmployeeQuery;
import com.usefullc.user.service.EmployeeService;
import com.usefullc.user.service.UserService;
import com.usefullc.user.vo.EmployeeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Sampson
 * @date: 2022-04-15 15:28
 */
@RestController
@RequestMapping(path = "/admin/employee/")
@Api( tags="人员管理[超级管理员]")
public class AdminEmployeeController extends BaseController {

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private UserService userService;


    @ApiOperationSupport(author = "Sampson@usefullc.com")
    @ApiOperation(value = "获取列表", response = WebResult.class)
    @GetMapping(path = "list", produces = "application/json")
    public WebResult list(EmployeeQuery query) {
        Pager<EmployeeVo> pager = employeeService.findVoByPage(query);
        return WebResultBuilder.successResult(pager);
    }


    @ApiOperation(value = "保存人员", response = WebResult.class)
    @PostMapping(path = "save", produces = "application/json")
    public WebResult save(@UsefulValid(save = true) @RequestBody EmployeeEditParam param) {
//        param.setType(UserTypeEnum.ADMIN.getCode());
        employeeService.saveEmployee(param);
        return WebResultBuilder.successResult();
    }

    @ApiOperation(value = "修改人员", response = WebResult.class)
    @PostMapping(path = "update", produces = "application/json")
    public WebResult update(@UsefulValid(update = true) @RequestBody EmployeeEditParam param) {
//        User user = this.userService.findById(param.getId());
//        BeanUtils.beanCopy(param,user);  //todo 待优化
        return save(param);
    }




    @ApiOperation(value = "删除人员", response = WebResult.class)
    @PostMapping(path = "del", produces = "application/json")
    public WebResult del(@UsefulValid(del = true) @RequestBody IdsParam idsParam) {
        employeeService.deletePhysByIds(idsParam.getIds());
        return WebResultBuilder.successResult();
    }


}
